<HTML>
<BODY>
<PRE>
<!-- Manpage converted by man2html 3.0.1 -->

<B><A HREF="BIND.html">BIND(2)</A></B> 		  FreeBSD System Calls Manual		       <B><A HREF="BIND.html">BIND(2)</A></B>


</PRE>
<H2>NAME</H2><PRE>
     <B>bind</B> - bind a name to a socket


</PRE>
<H2>SYNOPSIS</H2><PRE>
     <B>#include</B> <B>&lt;sys/types.h&gt;</B>
     <B>#include</B> <B>&lt;sys/socket.h&gt;</B>

     <I>int</I>
     <B>bind</B>(<I>int</I> <I>s</I>, <I>const</I> <I>struct</I> <I>sockaddr</I> <I>*name</I>, <I>int</I> <I>namelen</I>)


</PRE>
<H2>DESCRIPTION</H2><PRE>
     <B>Bind</B>() assigns a name to an unnamed socket.  When a socket is created
     with <B><A HREF="socket.html">socket(2)</A></B> it exists in a name space (address family) but has no name
     assigned.	<B>Bind</B>() requests that <I>name</I> be assigned to the socket.


</PRE>
<H2>NOTES</H2><PRE>
     Binding a name in the UNIX domain creates a socket in the file system
     that must be deleted by the caller when it is no longer needed (using
     <B><A HREF="unlink.html">unlink(2)</A></B>).

     The rules used in name binding vary between communication domains.  Con-
     sult the manual entries in section 4 for detailed information.


</PRE>
<H2>IMPLEMENTATION NOTES</H2><PRE>
     In the non-threaded library <B>bind</B>() is implemented as the <I>bind</I> syscall.

     In the threaded library, the <I>bind</I> syscall is assembled to
     <B>_thread_sys_bind</B>() and <B>bind</B>() is implemented as a function which locks <I>s</I>
     for read and write, then calls <B>_thread_sys_bind</B>().  Before returning,
     <B>bind</B>() unlocks <I>s</I>.


</PRE>
<H2>RETURN VALUES</H2><PRE>
     If the bind is successful, a 0 value is returned.	A return value of -1
     indicates an error, which is further specified in the global <I>errno</I>.


</PRE>
<H2>ERRORS</H2><PRE>
     The <B>bind</B>() call will fail if:

     [EBADF]	  <I>S</I> is not a valid descriptor.

     [ENOTSOCK]   <I>S</I> is not a socket.

     [EADDRNOTAVAIL]
		  The specified address is not available from the local ma-
		  chine.

     [EADDRINUSE]
		  The specified address is already in use.

     [EACCES]	  The requested address is protected, and the current user has
		  inadequate permission to access it.

     [EFAULT]	  The <I>name</I> parameter is not in a valid part of the user ad-
		  dress space.

     The following errors are specific to binding names in the UNIX domain.

     [ENOTDIR]	  A component of the path prefix is not a directory.

     [EINVAL]	  The pathname contains a character with the high-order bit

		  set.

     [ENAMETOOLONG]
		  A component of a pathname exceeded 255 characters, or an en-
		  tire path name exceeded 1023 characters.

     [ENOENT]	  A prefix component of the path name does not exist.

     [ELOOP]	  Too many symbolic links were encountered in translating the
		  pathname.

     [EIO]	  An I/O error occurred while making the directory entry or
		  allocating the inode.

     [EROFS]	  The name would reside on a read-only file system.

     [EISDIR]	  An empty pathname was specified.


</PRE>
<H2>SEE ALSO</H2><PRE>
     <B><A HREF="connect.html">connect(2)</A></B>,  <B><A HREF="getsockname.html">getsockname(2)</A></B>,  <B><A HREF="listen.html">listen(2)</A></B>,  <B><A HREF="socket.html">socket(2)</A></B>


</PRE>
<H2>HISTORY</H2><PRE>
     The <B>bind</B>() function call appeared in 4.2BSD.

4.2 Berkeley Distribution	 June 4, 1993				     2
</PRE>
<HR>
<ADDRESS>
Man(1) output converted with
<a href="http://www.oac.uci.edu/indiv/ehood/man2html.html">man2html</a>
</ADDRESS>
</BODY>
</HTML>
